<template>
  <view class="page">
    <view class="btn-box flexR">
      <text @click="save">下载PDF</text>
      <!-- <text>下载为图片</text> -->
    </view>
    <view class="wbv" style="position: relative;">
      <!-- <web-view :src="`/static/pdfjs/web/viewer.html?file=${url}`"></web-view> -->
      <iframe :src="`/wxapp/static/pdfjs/web/viewer.html?file=${url}`"></iframe>
    </view>
  </view>
</template>

<script>
  export default {
    data() {
      return {
        url: ''
      }
    },
    onLoad() {
      this.viewFile()
    },
    methods: {
      viewFile() {
        uni.request({
          // url: '/wxapp/static/content.pdf',
          url: 'https://cloudimg.hsop.site:18000/api/files//REPFS/2021/12/24/896631/2076980/100820309.pdf',
          method: "GET",
          responseType: 'arraybuffer',
          // header: {
          //   fileType: 'pdf',
          // },
          success: (response) => {
            console.log(999999, response)
            let pdfData = response.data; //pdfData是后端返回的文件流
            let blob = new Blob([ pdfData], {
              type: 'application/pdf;charset=UTF-8'
            })
            pdfData = window.URL.createObjectURL(blob) //创建预览路径
            this.url = encodeURIComponent(pdfData)
            console.log(pdfData)
          }
        });
      },
      save() {
        // this.downloadIamge(this.report.fileName, this.report.patientName + '.png')
        window.location.href='https://cloudimg.hsop.site:18000/api/files//REPFS/2021/12/24/896631/2076980/100820309.pdf'
        // this.downloadFileForm('https://cloudimg.hsop.site:18000/api/files//REPFS/2021/12/24/896631/2076980/100820309.pdf')
      },
    }
  }
</script>

<style lang="scss" scoped>
.wbv {
  // position: relative;
  // height: 500upx;
  // width: 100%;
  iframe {
    width: 100%;
    height: 1000upx;
    border: none;
    outline: none;
  }
}
.btn-box {
  justify-content: flex-end;
  color: $theme-color;
  gap: 24upx;
  margin-bottom: 24upx;
}
</style>
